package com.lineage.server.clientpackets;

import com.add.L1PcUnlock;
import com.lineage.config.ConfigAlt;
import com.lineage.config.ConfigClan;
import com.lineage.config.ConfigOther;
import com.lineage.echo.ClientExecutor;
import com.lineage.server.datatables.CharObjidTable;
import com.lineage.server.datatables.ClanMembersTable;
import com.lineage.server.datatables.NpcTable;
import com.lineage.server.datatables.QuestMapTable;
import com.lineage.server.datatables.RecordTable;
import com.lineage.server.datatables.lock.ClanAllianceReading;
import com.lineage.server.datatables.lock.HouseReading;
import com.lineage.server.datatables.lock.PetReading;
import com.lineage.server.datatables.sql.CharacterTable;
import com.lineage.server.model.Instance.L1EffectInstance;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.Instance.L1PetInstance;
import com.lineage.server.model.L1Alliance;
import com.lineage.server.model.L1CastleLocation;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1ChatParty;
import com.lineage.server.model.L1Clan;
import com.lineage.server.model.L1ClanJoin;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1Party;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.L1War;
import com.lineage.server.model.map.L1Map;
import com.lineage.server.serverpackets.S_Bonusstats;
import com.lineage.server.serverpackets.S_ChangeName;
import com.lineage.server.serverpackets.S_CharReset;
import com.lineage.server.serverpackets.S_CharTitle;
import com.lineage.server.serverpackets.S_CharVisualUpdate;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_Message_YN;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_OwnCharStatus2;
import com.lineage.server.serverpackets.S_PacketBox;
import com.lineage.server.serverpackets.S_Resurrection;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.S_Trade;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1House;
import com.lineage.server.templates.L1Npc;
import com.lineage.server.templates.L1Pet;
import com.lineage.server.thread.GeneralThreadPool;
import com.lineage.server.timecontroller.server.ServerWarExecutor;
import com.lineage.server.utils.FaceToFace;
import com.lineage.server.world.World;
import com.lineage.server.world.WorldClan;
import com.lineage.server.world.WorldWar;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_Attr extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_Attr.class);
  
  private static void renamePet(L1PetInstance pet, String name) {
    if (pet == null || name == null)
      throw new NullPointerException(); 
    int petItemObjId = pet.getItemObjId();
    L1Pet petTemplate = PetReading.get().getTemplate(petItemObjId);
    if (petTemplate == null)
      throw new NullPointerException(); 
    L1PcInstance pc = (L1PcInstance)pet.getMaster();
    if (PetReading.get().isNameExists(name)) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(327));
      return;
    } 
    L1Npc l1npc = NpcTable.get().getTemplate(pet.getNpcId());
    if (!pet.getName().equalsIgnoreCase(l1npc.get_name())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(326));
      return;
    } 
    pet.setName(name);
    petTemplate.set_name(name);
    PetReading.get().storePet(petTemplate);
    L1ItemInstance item = pc.getInventory().getItem(pet.getItemObjId());
    pc.getInventory().updateItem(item);
    pc.sendPacketsAll((ServerBasePacket)new S_ChangeName(pet.getId(), name));
  }
  
  private static boolean isInWarAreaAndWarTime(L1PcInstance pc) {
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)pc);
    return (castleId != 0 && ServerWarExecutor.get().isNowWar(castleId));
  }
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      int m;
      L1PcInstance leavePc;
      int k;
      L1PcInstance alliancePc;
      int c;
      L1PcInstance joinPc;
      boolean loginLeader;
      int i1;
      L1PcInstance enemyLeader, trading_partner, resusepc1, resusepc2;
      String petName, houseName;
      L1PcInstance fightPc, target653, partner;
      int cost, n;
      L1PcInstance chatPc, target654;
      String s, clan_name, clanName;
      L1PcInstance target_partner;
      L1EffectInstance tomb2;
      int houseId, level;
      L1Clan clan;
      String enemyClanName;
      int lawful;
      L1PcInstance[] clanMember;
      int i, j;
      read(decrypt);
      L1PcInstance pc = client.getActiveChar();
      if (pc.isGhost() || pc.isTeleport())
        return; 
      int mode = readH();
      int tgobjid = 0;
      if (mode == 0) {
        tgobjid = readD();
        mode = readH();
      } 
      switch (mode) {
        case 97:
          m = readC();
          joinPc = (L1PcInstance)World.get().findObject(pc.getTempID());
          pc.setTempID(0);
          if (joinPc == null)
            break; 
          if (m == 0) {
            joinPc.sendPackets((ServerBasePacket)new S_ServerMessage(96, pc.getName()));
            break;
          } 
          if (m == 1)
            L1ClanJoin.getInstance().ClanJoin(pc, joinPc); 
          break;
        case 1906:
          m = readC();
          if (m == 0) {
            leaveClan(pc, false);
            break;
          } 
          loginLeader = false;
          clan_name = pc.getClanname();
          clan = WorldClan.get().getClan(clan_name);
          clanMember = clan.getOnlineClanMember();
          i = 0;
          while (i < clanMember.length) {
            if (clanMember[i].getClanRank() == 4 || clanMember[i].getClanRank() == 3 || 
              clanMember[i].getClanRank() == 10) {
              clanMember[i].setTempID(pc.getId());
              clanMember[i].sendPackets((ServerBasePacket)new S_Message_YN(1908, pc.getName()));
              loginLeader = true;
            } 
            i++;
          } 
          if (loginLeader) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(1907));
            break;
          } 
          pc.sendPackets((ServerBasePacket)new S_Message_YN(1914));
          break;
        case 1908:
          leavePc = (L1PcInstance)World.get().findObject(pc.getTempID());
          i1 = readC();
          if (i1 == 0) {
            clan_name = pc.getClanname();
            clan = WorldClan.get().getClan(clan_name);
            clanMember = clan.getOnlineClanMember();
            int i2 = 0;
            while (i2 < clanMember.length) {
              clanMember[i2].sendPackets((ServerBasePacket)new S_ServerMessage(1917, pc.getName(), leavePc.getName()));
              i2++;
            } 
            leavePc.sendPackets((ServerBasePacket)new S_Message_YN(1912));
            break;
          } 
          clan_name = pc.getClanname();
          clan = WorldClan.get().getClan(clan_name);
          clanMember = clan.getOnlineClanMember();
          j = 0;
          while (j < clanMember.length) {
            clanMember[j].sendPackets((ServerBasePacket)new S_ServerMessage(1916, pc.getName(), leavePc.getName()));
            j++;
          } 
          leaveClan(leavePc, true);
          break;
        case 1912:
        case 1914:
          k = readC();
          if (k == 0)
            return; 
          leaveClan(pc, false);
          break;
        case 217:
        case 221:
        case 222:
          k = readC();
          enemyLeader = (L1PcInstance)World.get().findObject(pc.getTempID());
          if (enemyLeader == null)
            return; 
          pc.setTempID(0);
          clanName = pc.getClanname();
          enemyClanName = enemyLeader.getClanname();
          if (k == 0) {
            if (mode == 217) {
              enemyLeader.sendPackets((ServerBasePacket)new S_ServerMessage(236, clanName));
              break;
            } 
            if (mode == 221 || mode == 222)
              enemyLeader.sendPackets((ServerBasePacket)new S_ServerMessage(237, clanName)); 
            break;
          } 
          if (k != 1)
            break; 
          if (mode == 217) {
            L1War war = new L1War();
            war.handleCommands(2, enemyClanName, clanName);
            break;
          } 
          if (mode == 221 || mode == 222) {
            Iterator<L1War> iterator = WorldWar.get().getWarList().iterator();
            while (iterator.hasNext()) {
              L1War war = iterator.next();
              if (war.checkClanInWar(clanName)) {
                if (mode == 221) {
                  war.surrenderWar(enemyClanName, clanName);
                  break;
                } 
                if (mode == 222)
                  war.ceaseWar(enemyClanName, clanName); 
                break;
              } 
            } 
          } 
          break;
        case 252:
          k = readC();
          trading_partner = (L1PcInstance)World.get().findObject(pc.getTradeID());
          target_partner = FaceToFace.faceToFace(pc);
          if (trading_partner != null && target_partner != null && 
            target_partner.getId() == trading_partner.getId()) {
            if (k == 0) {
              if (pc.hasSkillEffect(51234)) {
                trading_partner.sendPackets((ServerBasePacket)new S_ServerMessage(253, "尿尿商人"));
              } else {
                trading_partner.sendPackets((ServerBasePacket)new S_ServerMessage(253, pc.getName()));
              } 
              pc.setTradeID(0);
              trading_partner.setTradeID(0);
              break;
            } 
            if (k != 1)
              break; 
            if (trading_partner.hasSkillEffect(51234)) {
              pc.sendPackets((ServerBasePacket)new S_Trade("尿尿商人"));
              trading_partner.sendPackets((ServerBasePacket)new S_Trade(pc.getName()));
              break;
            } 
            pc.sendPackets((ServerBasePacket)new S_Trade(trading_partner.getName()));
            trading_partner.sendPackets((ServerBasePacket)new S_Trade(pc.getName()));
            break;
          } 
          pc.setTradeID(0);
          if (trading_partner != null)
            trading_partner.setTradeID(0); 
          break;
        case 321:
          k = readC();
          resusepc1 = (L1PcInstance)World.get().findObject(pc.getTempID());
          pc.setTempID(0);
          if (resusepc1 == null)
            break; 
          if (k == 0)
            break; 
          if (k == 1) {
            L1EffectInstance tomb = pc.get_tomb();
            if (tomb != null) {
              tomb.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(tomb.getId(), 8));
              tomb.deleteMe();
            } 
            pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 230));
            pc.resurrect(pc.getMaxHp() / 2);
            pc.setCurrentHp(pc.getMaxHp() / 2);
            pc.startHpRegeneration();
            pc.startMpRegeneration();
            pc.stopPcDeleteTimer();
            pc.sendPacketsAll((ServerBasePacket)new S_Resurrection(pc, (L1Character)resusepc1, 0));
            pc.sendPacketsAll((ServerBasePacket)new S_CharVisualUpdate(pc));
          } 
          break;
        case 322:
          k = readC();
          resusepc2 = (L1PcInstance)World.get().findObject(pc.getTempID());
          pc.setTempID(0);
          if (resusepc2 == null)
            break; 
          if (k == 0)
            break; 
          if (k != 1)
            break; 
          tomb2 = pc.get_tomb();
          if (tomb2 != null) {
            tomb2.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(tomb2.getId(), 8));
            tomb2.deleteMe();
          } 
          pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 230));
          pc.resurrect(pc.getMaxHp());
          pc.setCurrentHp(pc.getMaxHp());
          pc.startHpRegeneration();
          pc.startMpRegeneration();
          pc.stopPcDeleteTimer();
          pc.sendPacketsAll((ServerBasePacket)new S_Resurrection(pc, (L1Character)resusepc2, 0));
          pc.sendPacketsAll((ServerBasePacket)new S_CharVisualUpdate(pc));
          if (pc.getExpRes() == 1 && pc.isGres() && pc.isGresValid()) {
            pc.resExp();
            pc.setExpRes(0);
            pc.setGres(false);
          } 
          break;
        case 325:
          k = readC();
          petName = readS();
          if (pc.is_rname()) {
            String name = Matcher.quoteReplacement(petName);
            name = name.replaceAll("\\s", "");
            name = name.replaceAll("　", "");
            name = String.valueOf(String.valueOf(name.substring(0, 1).toUpperCase())) + name.substring(1);
            String[] banlist;
            int length = (banlist = C_CreateChar.BANLIST).length;
            int i2 = 0;
            while (i2 < length) {
              String ban = banlist[i2];
              if (name.indexOf(ban) != -1)
                name = ""; 
              i2++;
            } 
            if (name.length() == 0) {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(53));
              return;
            } 
            if (!C_CreateChar.isInvalidName(name)) {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(53));
              return;
            } 
            if (CharObjidTable.get().charObjid(name) != 0) {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(58));
              return;
            } 
            World.get().removeObject((L1Object)pc);
            pc.getInventory().consumeItem(41227, 1L);
            RecordTable.get().recordPcChangeName(pc.getId(), pc.getAccountName(), pc.getName(), name, 
                pc.getIp());
            pc.setName(name);
            CharObjidTable.get().reChar(pc.getId(), name);
            CharacterTable.get().newCharName(pc.getId(), name);
            World.get().storeObject((L1Object)pc);
            pc.sendPacketsAll((ServerBasePacket)new S_ChangeName(pc, true));
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "由于人物名称异动!请重新登入游戏!将于5秒后强制断线!"));
            KickPc kickPc = new KickPc(pc);
            kickPc.start_cmd();
          } else {
            L1PetInstance pet = (L1PetInstance)World.get().findObject(pc.getTempID());
            pc.setTempID(0);
            renamePet(pet, petName);
          } 
          pc.rename(false);
          break;
        case 512:
          k = readC();
          houseName = readS();
          houseId = pc.getTempID();
          pc.setTempID(0);
          if (houseName.length() <= 16) {
            L1House house = HouseReading.get().getHouseTable(houseId);
            house.setHouseName(houseName);
            HouseReading.get().updateHouse(house);
            break;
          } 
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(513));
          break;
        case 630:
          k = readC();
          fightPc = (L1PcInstance)World.get().findObject(pc.getFightId());
          if (k == 0) {
            pc.setFightId(0);
            fightPc.setFightId(0);
            fightPc.sendPackets((ServerBasePacket)new S_ServerMessage(631, pc.getName()));
            break;
          } 
          if (k == 1) {
            fightPc.sendPackets((ServerBasePacket)new S_PacketBox(5, fightPc.getFightId(), fightPc.getId()));
            pc.sendPackets((ServerBasePacket)new S_PacketBox(5, pc.getFightId(), pc.getId()));
          } 
          break;
        case 653:
          k = readC();
          target653 = (L1PcInstance)World.get().findObject(pc.getPartnerId());
          if (k == 0)
            return; 
          if (k == 1)
            if (target653 != null) {
              target653.setPartnerId(0);
              target653.save();
              target653.sendPackets((ServerBasePacket)new S_ServerMessage(662));
            } else {
              CharacterTable.get();
              CharacterTable.updatePartnerId(pc.getPartnerId());
            }  
          pc.setPartnerId(0);
          pc.save();
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(662));
          break;
        case 654:
          k = readC();
          partner = (L1PcInstance)World.get().findObject(pc.getTempID());
          pc.setTempID(0);
          if (partner == null)
            break; 
          if (k == 0) {
            partner.sendPackets((ServerBasePacket)new S_ServerMessage(656, pc.getName()));
            break;
          } 
          if (k == 1) {
            pc.setPartnerId(partner.getId());
            pc.save();
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(790));
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(655, partner.getName()));
            partner.setPartnerId(pc.getId());
            partner.save();
            partner.sendPackets((ServerBasePacket)new S_ServerMessage(790));
            partner.sendPackets((ServerBasePacket)new S_ServerMessage(655, pc.getName()));
            Iterator<L1PcInstance> iterator2 = World.get().getAllPlayers().iterator();
            while (iterator2.hasNext()) {
              L1PcInstance allpc = iterator2.next();
              if (allpc != null) {
                allpc.sendPackets(
                    (ServerBasePacket)new S_SystemMessage("恭喜 " + pc.getName() + " 与 " + partner.getName() + " 结为夫妻。"));
                allpc.sendPackets((ServerBasePacket)new S_SystemMessage("让我们一起为这对新人送上最真挚的祝福。"));
              } 
            } 
          } 
          break;
        case 729:
          k = readC();
          if (k == 0) {
            int objId = pc.getTempID();
            Collection<L1PcInstance> allPc = World.get().getAllPlayers();
            Iterator<L1PcInstance> iterator3 = allPc.iterator();
            while (iterator3.hasNext()) {
              L1PcInstance each = iterator3.next();
              if (each.getId() == objId) {
                each.sendPackets((ServerBasePacket)new S_ServerMessage("对方拒绝了你的呼唤。"));
                break;
              } 
            } 
            if (pc.getcallclanal() > 0)
              pc.setcallclanal(0); 
            pc.setTempID(0);
            break;
          } 
          if (k != 1)
            break; 
          if (pc.getcallclanal() <= 0) {
            callClan(pc);
            break;
          } 
          if (!pc.getInventory().checkItem(ConfigOther.target_clan_itemid, ConfigOther.target_clan_count)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(ConfigOther.clanmsg2));
            return;
          } 
          if (!pc.getInventory().checkItem(ConfigOther.target_clan_itemid, ConfigOther.target_clan_count)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(ConfigOther.alliancemsg2));
            return;
          } 
          if (!pc.getMap().isAlliancePc()) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
            return;
          } 
          if (!pc.getMap().isClanPc()) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
            return;
          } 
          if (isInWarAreaAndWarTime(pc)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("旗子内禁止使用"));
            return;
          } 
          callClan1(pc);
          break;
        case 4000:
          k = readC();
          if (k == 0) {
            int objId = pc.getTempID();
            Collection<L1PcInstance> allPc = World.get().getAllPlayers();
            Iterator<L1PcInstance> iterator4 = allPc.iterator();
            while (iterator4.hasNext()) {
              L1PcInstance each = iterator4.next();
              if (each.getId() == objId) {
                each.sendPackets((ServerBasePacket)new S_ServerMessage("对方拒绝了你的呼唤。"));
                break;
              } 
            } 
            if (pc.getcallclanal() > 0)
              pc.setcallclanal(0); 
            pc.setTempID(0);
            break;
          } 
          if (k != 1 || pc.getcallclanal() <= 0)
            break; 
          if (!pc.getInventory().checkItem(ConfigOther.target_party_itemid, ConfigOther.target_party_count)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(ConfigOther.clanmsg6));
            return;
          } 
          if (!pc.getMap().isPartyPc()) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
            return;
          } 
          if (isInWarAreaAndWarTime(pc)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("旗子内禁止使用"));
            return;
          } 
          callpartyall(pc);
          break;
        case 738:
          k = readC();
          if (k == 0)
            break; 
          if (k != 1 || pc.getExpRes() != 1)
            break; 
          cost = 0;
          level = pc.getLevel();
          lawful = pc.getLawful();
          if (level < 45) {
            cost = level * level * 100;
          } else {
            cost = level * level * 200;
          } 
          if (lawful >= 0)
            cost /= 2; 
          if (pc.getInventory().consumeItem(40308, cost)) {
            pc.resExp();
            pc.setExpRes(0);
            break;
          } 
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(189));
          break;
        case 223:
          alliancePc = (L1PcInstance)World.get().findObject(pc.getTempID());
          pc.setTempID(0);
          if (alliancePc == null)
            return; 
          n = readC();
          if (n == 1) {
            L1Clan user_clan = pc.getClan();
            if (user_clan == null || pc.getId() != user_clan.getLeaderId()) {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(518));
              return;
            } 
            L1Clan target_clan = alliancePc.getClan();
            if (target_clan == null)
              return; 
            L1Alliance alliance = ClanAllianceReading.get().getAlliance(user_clan.getClanId());
            if (alliance == null) {
              alliance = new L1Alliance(user_clan.getClanId(), new L1Clan[] { user_clan, target_clan });
              ClanAllianceReading.get().insertAlliance(alliance);
            } else {
              if (!alliance.checkSize()) {
                alliancePc.sendPackets((ServerBasePacket)new S_ServerMessage(1201));
                return;
              } 
              alliance.addAlliance(target_clan);
              ClanAllianceReading.get().updateAlliance(alliance.getOrderId(), alliance.getTotalList());
            } 
            World.get().broadcastPacketToAll(
                (ServerBasePacket)new S_ServerMessage(224, user_clan.getClanName(), target_clan.getClanName()));
            alliance.sendPacketsAll("", (ServerBasePacket)new S_ServerMessage(1200, target_clan.getClanName()));
            break;
          } 
          if (n == 0)
            alliancePc.sendPackets((ServerBasePacket)new S_ServerMessage(1198)); 
          break;
        case 748:
          if (pc.hasSkillEffect(87)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上有冲击之晕状态，无法使用穿云箭"));
            break;
          } 
          if (pc.hasSkillEffect(66))
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上有沉睡之雾状态，无法使用穿云箭")); 
          if (!pc.hasSkillEffect(1692)) {
            int newX = pc.getTeleportX();
            int newY = pc.getTeleportY();
            short mapId = pc.getTeleportMapId();
            L1Teleport.teleport(pc, newX, newY, mapId, 5, true);
            break;
          } 
          if (pc.hasSkillEffect(50)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上有冰茅围篱状态，无法使用穿云箭"));
            break;
          } 
          if (pc.hasSkillEffect(33)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上有木乃伊的诅咒状态，无法使用穿云箭"));
            break;
          } 
          if (pc.hasSkillEffect(157)) {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上有木乃伊的诅咒状态，无法使用穿云箭"));
            break;
          } 
          c = readC();
          if (c == 0)
            break; 
          if (c == 1) {
            int newX = pc.getTeleportX();
            int newY = pc.getTeleportY();
            short mapId = pc.getTeleportMapId();
            L1Teleport.teleport(pc, newX, newY, mapId, 5, true);
          } 
          break;
        case 951:
          c = readC();
          chatPc = (L1PcInstance)World.get().findObject(pc.getPartyID());
          if (chatPc == null)
            break; 
          if (c == 0) {
            chatPc.sendPackets((ServerBasePacket)new S_ServerMessage(423, pc.getName()));
            pc.setPartyID(0);
            break;
          } 
          if (c != 1)
            break; 
          if (!chatPc.isInChatParty()) {
            L1ChatParty chatParty = new L1ChatParty();
            chatParty.addMember(chatPc);
            chatParty.addMember(pc);
            chatPc.sendPackets((ServerBasePacket)new S_ServerMessage(424, pc.getName()));
            break;
          } 
          if (chatPc.getChatParty().isVacancy() || chatPc.isGm()) {
            chatPc.getChatParty().addMember(pc);
            break;
          } 
          chatPc.sendPackets((ServerBasePacket)new S_ServerMessage(417));
          break;
        case 953:
          c = readC();
          target654 = (L1PcInstance)World.get().findObject(pc.getPartyID());
          if (target654 == null)
            break; 
          if (c == 0) {
            target654.sendPackets((ServerBasePacket)new S_ServerMessage(423, pc.getName()));
            pc.setPartyID(0);
            break;
          } 
          if (c != 1)
            break; 
          if (!target654.isInParty()) {
            L1Party party = new L1Party();
            party.addMember(target654);
            party.addMember(pc);
            target654.sendPackets((ServerBasePacket)new S_ServerMessage(424, pc.getName()));
            break;
          } 
          if (target654.getParty().isVacancy()) {
            target654.getParty().addMember(pc);
            break;
          } 
          target654.sendPackets((ServerBasePacket)new S_ServerMessage(417));
          break;
        case 479:
          c = readC();
          if (c != 1)
            break; 
          s = readS();
          if (pc.getLevel() - 50 <= pc.getBonusStats())
            return; 
          if (s.equalsIgnoreCase("str")) {
            if (pc.getBaseStr() < ConfigAlt.POWER) {
              pc.addBaseStr(1);
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } else if (s.equalsIgnoreCase("dex")) {
            if (pc.getBaseDex() < ConfigAlt.POWER) {
              pc.addBaseDex(1);
              pc.resetBaseAc();
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } else if (s.equalsIgnoreCase("con")) {
            if (pc.getBaseCon() < ConfigAlt.POWER) {
              pc.addBaseCon(1);
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } else if (s.equalsIgnoreCase("int")) {
            if (pc.getBaseInt() < ConfigAlt.POWER) {
              pc.addBaseInt(1);
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } else if (s.equalsIgnoreCase("wis")) {
            if (pc.getBaseWis() < ConfigAlt.POWER) {
              pc.addBaseWis(1);
              pc.resetBaseMr();
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } else if (s.equalsIgnoreCase("cha")) {
            if (pc.getBaseCha() < ConfigAlt.POWER) {
              pc.addBaseCha(1);
              pc.setBonusStats(pc.getBonusStats() + 1);
              pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
              pc.sendPackets((ServerBasePacket)new S_CharVisualUpdate(pc));
              pc.save();
            } else {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage("属性最大值只能到" + ConfigAlt.POWER + "。 请重试一次。"));
            } 
          } 
          if (pc.power())
            pc.sendPackets((ServerBasePacket)new S_Bonusstats(pc.getId())); 
          break;
        case 1210:
          if (readC() == 1) {
            L1Clan user_clan = pc.getClan();
            if (user_clan == null || pc.getId() != user_clan.getLeaderId()) {
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(518));
              return;
            } 
            L1Alliance alliance = ClanAllianceReading.get().getAlliance(user_clan.getClanId());
            if (alliance == null)
              return; 
            for (L1Clan l1clan : alliance.getTotalList()) {
              if (l1clan.getClanId() == user_clan.getClanId()) {
                alliance.getTotalList().remove(l1clan);
                break;
              } 
            } 
            if (alliance.getTotalList().size() < 2) {
              ClanAllianceReading.get().deleteAlliance(alliance.getOrderId());
            } else {
              ClanAllianceReading.get().updateAlliance(alliance.getOrderId(), alliance.getTotalList());
            } 
            World.get().broadcastPacketToAll((ServerBasePacket)new S_ServerMessage(225, (
                  (L1Clan)alliance.getTotalList().get(0)).getClanName(), user_clan.getClanName()));
            alliance.sendPacketsAll("", (ServerBasePacket)new S_ServerMessage(1204, user_clan.getClanName()));
          } 
          break;
        case 3312:
          c = readC();
          if (c == 1) {
            pc.getInventory().consumeItem(ConfigOther.checkitem76, ConfigOther.checkitemcount76);
            pc.getQuest().set_step(58003, 1);
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), "slot9"));
          } 
          break;
        case 3313:
          c = readC();
          if (c == 1) {
            pc.getInventory().consumeItem(ConfigOther.checkitem81, ConfigOther.checkitemcount81);
            pc.getQuest().set_step(58002, 1);
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), "slot9"));
          } 
          break;
        case 3589:
          c = readC();
          if (c == 1) {
            pc.getInventory().consumeItem(ConfigOther.checkitem59, ConfigOther.checkitemcount59);
            pc.getQuest().set_step(58001, 1);
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), "slot9"));
          } 
          break;
        case 1268:
          if (pc.getLevel() <= 29 || pc.getLevel() >= 52)
            pc.getLevel(); 
          break;
      } 
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  private void leaveClan(L1PcInstance leavePc, boolean isApproved) {
    String clan_name = leavePc.getClanname();
    L1Clan clan = WorldClan.get().getClan(clan_name);
    L1PcInstance[] clanMember = clan.getOnlineClanMember();
    int i = 0;
    while (i < clanMember.length) {
      clanMember[i].sendPackets((ServerBasePacket)new S_ServerMessage(178, leavePc.getName(), clan_name));
      i++;
    } 
    if (clan.getWarehouseUsingChar() == leavePc.getId())
      clan.setWarehouseUsingChar(0); 
    try {
      long time = 0L;
      if (isApproved) {
        time = 0L;
      } else {
        time = 60000L;
      } 
      leavePc.setClanid(0);
      leavePc.setClanname("");
      leavePc.setClanRank(0);
      leavePc.setClanMemberId(0);
      leavePc.setClanMemberNotes("");
      if (ConfigClan.clandelt)
        leavePc.setPcContribution(0); 
      leavePc.setClanContribution(0);
      leavePc.setClanNameContribution("");
      leavePc.sendPacketsAll((ServerBasePacket)new S_CharTitle(leavePc.getId(), ""));
      leavePc.sendPacketsAll((ServerBasePacket)new S_CharReset(leavePc.getId(), 0));
      leavePc.save();
      L1PcUnlock.Pc_Unlock(leavePc);
      clan.delMemberName(leavePc.getName());
      ClanMembersTable.getInstance().deleteMember(leavePc.getId());
      leavePc.setRejoinClanTime(new Timestamp(System.currentTimeMillis() + time));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  private void callClan(L1PcInstance pc) {
    L1PcInstance callClanPc = (L1PcInstance)World.get().findObject(pc.getTempID());
    pc.setTempID(0);
    if (pc.isParalyzedX())
      return; 
    if (callClanPc == null)
      return; 
    if (!pc.getMap().isEscapable() && !pc.isGm()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(647));
      return;
    } 
    if (pc.getId() != callClanPc.getCallClanId())
      return; 
    boolean isInWarArea = false;
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)callClanPc);
    if (castleId != 0) {
      isInWarArea = true;
      if (ServerWarExecutor.get().isNowWar(castleId))
        isInWarArea = false; 
    } 
    short mapId = callClanPc.getMapId();
    if ((mapId != 0 && mapId != 4 && mapId != 304) || isInWarArea) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(629));
      return;
    } 
    if (QuestMapTable.get().isQuestMap(pc.getMapId())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(629));
      return;
    } 
	final int HEADING_TABLE_X[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
	final int HEADING_TABLE_Y[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
    L1Map map = callClanPc.getMap();
    int locX = callClanPc.getX();
    int locY = callClanPc.getY();
    int heading = callClanPc.getCallClanHeading();
    locX += HEADING_TABLE_X[heading];
    locY += HEADING_TABLE_Y[heading];
    heading = (heading + 4) % 4;
    boolean isExsistCharacter = false;
    Iterator<L1Object> iterator = World.get().getVisibleObjects((L1Object)callClanPc, 1).iterator();
    while (iterator.hasNext()) {
      L1Object object = iterator.next();
      if (object instanceof L1Character) {
        L1Character cha = (L1Character)object;
        if (cha.getX() == locX && cha.getY() == locY && cha.getMapId() == mapId) {
          isExsistCharacter = true;
          break;
        } 
      } 
    } 
    if ((locX == 0 && locY == 0) || !map.isPassable(locX, locY, null) || isExsistCharacter) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(627));
      return;
    } 
    L1Teleport.teleport(pc, locX, locY, mapId, heading, true, 3);
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
  
  private void callClan1(L1PcInstance pc) {
    L1PcInstance callClanPc = (L1PcInstance)World.get().findObject(pc.getcallclanal());
    pc.setcallclanal(0);
    if (pc.isParalyzedX())
      return; 
    if (callClanPc == null)
      return; 
    if (pc.isParalyzedX())
      return; 
    boolean isInWarArea = false;
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)callClanPc);
    if (castleId != 0) {
      isInWarArea = true;
      if (ServerWarExecutor.get().isNowWar(castleId))
        isInWarArea = false; 
    } 
    if (isInWarArea) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(626));
      return;
    } 
    if (isInWarAreaAndWarTime(callClanPc)) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("对方旗子内,无法传送"));
      return;
    } 
    if (!callClanPc.getMap().isAlliancePc()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
      return;
    } 
    if (!callClanPc.getMap().isClanPc()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
      return;
    } 
    short mapId = callClanPc.getMapId();
    if (QuestMapTable.get().isQuestMap(pc.getMapId())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(626));
      return;
    } 
    pc.getInventory().consumeItem(ConfigOther.target_clan_itemid, ConfigOther.target_clan_count);
    int[] HEADING_TABLE_X =  { 0, 1, 1, 1, 0, -1, -1, -1 };
    int[] HEADING_TABLE_Y = { -1, -1, 0, 1, 1, 1, 0, -1 };
    L1Map map = callClanPc.getMap();
    int locX = callClanPc.getX();
    int locY = callClanPc.getY();
    int heading = callClanPc.getCallClanHeading();
    locX += HEADING_TABLE_X[heading];
    locY += HEADING_TABLE_Y[heading];
    heading = (heading + 4) % 4;
    L1Teleport.teleport(pc, locX, locY, mapId, heading, false);
  }
  
  private void callpartyall(L1PcInstance pc) {
    L1PcInstance callClanPc = (L1PcInstance)World.get().findObject(pc.getcallclanal());
    pc.setcallclanal(0);
    if (pc.isParalyzedX())
      return; 
    if (callClanPc == null)
      return; 
    if (pc.isParalyzedX())
      return; 
    boolean isInWarArea = false;
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)callClanPc);
    if (castleId != 0) {
      isInWarArea = true;
      if (ServerWarExecutor.get().isNowWar(castleId))
        isInWarArea = false; 
    } 
    short mapId = callClanPc.getMapId();
    if (isInWarArea) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(626));
      return;
    } 
    if (QuestMapTable.get().isQuestMap(pc.getMapId())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(626));
      return;
    } 
    if (isInWarAreaAndWarTime(callClanPc)) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("对方旗子内,无法传送"));
      return;
    } 
    if (!callClanPc.getMap().isPartyPc()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
      return;
    } 
    int[] HEADING_TABLE_X =  { 0, 1, 1, 1, 0, -1, -1, -1 };
    int[] HEADING_TABLE_Y = { -1, -1, 0, 1, 1, 1, 0, -1 };
    L1Map map = callClanPc.getMap();
    int locX = callClanPc.getX();
    int locY = callClanPc.getY();
    int heading = callClanPc.getCallClanHeading();
    locX += HEADING_TABLE_X[heading];
    locY += HEADING_TABLE_Y[heading];
    heading = (heading + 4) % 4;
    L1Teleport.teleport(pc, locX, locY, mapId, heading, false);
  }
  
  private class KickPc implements Runnable {
    private final ClientExecutor _client;
    
    private KickPc(L1PcInstance pc) {
      this._client = pc.getNetConnection();
    }
    
    private void start_cmd() {
      GeneralThreadPool.get().execute(this);
    }
    
    public void run() {
      try {
        Thread.sleep(5000L);
        this._client.kick();
      } catch (InterruptedException e) {
        C_Attr._log.error(e.getLocalizedMessage(), e);
      } 
    }
  }
}
